#include <string.h>
#include <iostream>
using std::cout;
using std::endl;

class Computer{
public:
    Computer(const char * brand,double price)
    : _brand(new char[strlen(brand) + 1]())
    , _price(price)
    {
        strcpy(_brand,brand);
        cout << "Computer(const char *,double)" << endl;
    }

    void print(){
        cout << "brand:" << _brand << endl
            << "price:" << _price << endl;
    }

    ~Computer(){
        if(_brand){
            delete [] _brand;
            _brand = nullptr;
        }
        cout << "~Computer()" << endl;
    }
private:
    char * _brand;
    double _price;
};


void test0(){
    int * p = nullptr;
    cout << p << endl;

    cout << sizeof(int) << endl;
    //类、对象占据的空间大小只与数据成员有关，
    //与成员函数无关（成员函数存在程序代码区中）
    cout << sizeof(Computer) << endl;
    Computer pc("Dell",7800);
    cout << sizeof(pc) << endl;
    printf("%p\n",&pc);
    pc.print();
    pc.~Computer();
    //char型空指针传给输出流运算符，会导致程序崩溃
    //输出流崩溃
    pc.print();//pc对象依然可以调用成员函数，说明pc对象没有被销毁
}

int main(void){
    test0();
    return 0;
}
